package zz.app.ustbgsmanager.adapters;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;

import zz.app.ustbgsmanager.R;
import zz.app.ustbgsmanager.beans.teachingassessment.CourseAssessment;
import zz.app.ustbgsmanager.fragments.CourseAssessmentFragment;

/**
 * Created by zz on 2018/6/11 15:35.
 */
public class TeachingAssessmentPagerAdapter extends FragmentPagerAdapter {
    private final Context context;
    private ArrayList<CourseAssessment> data;
    private CourseAssessmentFragment assessedFragment;
    private CourseAssessmentFragment notAssessedFragment;

    public TeachingAssessmentPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        this.context = context;
        Bundle bundle = new Bundle();
        bundle.putInt("pos", 0);
        assessedFragment = new CourseAssessmentFragment();
        assessedFragment.setArguments(bundle);
        Bundle bundle1 = new Bundle();
        bundle1.putInt("pos", 1);
        notAssessedFragment = new CourseAssessmentFragment();
        notAssessedFragment.setArguments(bundle1);
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0)
            return assessedFragment;
        else
            return notAssessedFragment;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        if (position == 0) {
            return context.getString(R.string.str_assessedcourse);
        } else {
            return context.getString(R.string.str_notassessedcourse);
        }
    }

    public void setData(ArrayList<CourseAssessment> data) {
        this.data = data;
        ArrayList<CourseAssessment> d1 = new ArrayList<>();
        ArrayList<CourseAssessment> d2 = new ArrayList<>();
        for (CourseAssessment d : data) {
            if (d.isAsessed()) {
                d1.add(d);
            } else {
                d2.add(d);
            }
        }
        assessedFragment.setData(d1);
        notAssessedFragment.setData(d2);
        notifyDataSetChanged();
    }
}
